package com.chuangke.quartz.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;
import com.chuangke.quartz.entity.SysJobLog;
import com.chuangke.quartz.service.SysJobLogService;

/**
 * 调度日志操作处理
 * 
 */
@RestController
@RequestMapping("/joblog")
public class SysJobLogController {

	@Autowired
	private SysJobLogService jobLogService;

	/**
	 * 查询定时任务调度日志列表
	 */
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping("/list")
	public HttpResult list(@RequestBody SysJobLog sysJobLog) {
		List<SysJobLog> list = jobLogService.list(sysJobLog);
		return HttpResult.ok(list);
	}

	/**
	 * 根据调度编号获取详细信息
	 */
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/{jobLogId}")
	public HttpResult getInfo(@PathVariable String jobLogId) {
		jobLogService.findById(jobLogId);
		return HttpResult.ok();
	}

	/**
	 * 删除定时任务调度日志
	 */
	@PreAuthorize("hasAuthority('login:action')")
	@PostMapping("/delete")
	public HttpResult remove(@RequestBody List<String> jobLogIds) {
		jobLogService.deleteByIds(jobLogIds);
		return HttpResult.ok();
	}

	/**
	 * 清空定时任务调度日志
	 */
	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping("/clean")
	public HttpResult clean() {
		jobLogService.cleanJobLog();
		return HttpResult.ok();
	}
}
